import request from '@/utils/request'
import type { GameType, GameRecord, Word, ApiResponse } from '@/types'

export const gameApi = {
  // 记录游戏结果
  recordGameResult(data: {
    gameType: GameType
    score: number
    correctCount?: number
    wrongCount?: number
    duration?: number
  }): Promise<ApiResponse> {
    return request.post('/game/record', data)
  },
  
  // 获取游戏历史记录
  getGameHistory(gameType?: GameType, limit?: number): Promise<ApiResponse<GameRecord[]>> {
    return request.get('/game/history', { params: { gameType, limit } })
  },
  
  // 获取游戏排行榜
  getGameLeaderboard(gameType: GameType, period?: string, limit?: number): Promise<ApiResponse> {
    return request.get('/game/leaderboard', { params: { gameType, period, limit } })
  },
  
  // 获取随机单词（用于游戏）
  getRandomWords(params?: {
    count?: number
    grade?: string
    difficulty?: string
  }): Promise<ApiResponse<Word[]>> {
    return request.get('/game/random-words', { params })
  }
}

